********************************************************************************
* This is one of the replication files for Attitudes Toward Voting-Rights      *
* requirements by Hultin Rosenberg and Wejryd								   *
*																			   *	
* It is to be run on the LONG dataset, in which each PROFILE is one unit,	   *
* and has the following purposes:										       *
* 1) reproduce Figures 2-4													   *
* 2) that numbers are referred in the article								   *
*																			   *
********************************************************************************

********************************************************************************
*							1. Figures 2-4									   *
********************************************************************************

*********************************************
* Preparations that are common for Fig. 2-4 *
*********************************************
* Clustering standard errors on respondent*
global ses ", cluster (ResponseId)"

* Install coefplot if not already done*
ssc install coefplot

* To reporoduce the style, get "lean-scheme": * 
lookup lean1 // Then activate lean1 and Times new roman by making a graph, 
// right-click it, and choose Alternatives.

*********************************************
* Figure 2: AMCEs for all attribute vaules  *
* (fig. 1 is a picture of respondents' task)*
*********************************************

reg chosen i.profilecitizenship i.profiletaxpayer  b5i.profileresidence ///
b5i.profileborn i.profileedu b2i.profilegender if use==1$ses

est sto _choicemodelisyntax

* PLOT 

coefplot _choicemodelisyntax, drop(?cons) xline(0) omitted baselevels ///
				headings(1.profilecitizenship = "{bf:Citizenship}" ///
						 1.profiletaxpayer = "{bf:Tax paying}" ///
						 1.profileresidence = "{bf:Residence}" ///
						 1.profileborn = "{bf:Country of origin}" ///
						 1.profileedu = "{bf:Education level equivalent to}" ///
						 1.profilegender = "{bf:Gender}") ///
mfcolor(white) lcolor(black*.7) xline(0) graphregion(fcolor(white)) ///
ciopts(lcolor(black) lwidth(*1)) msize(small) ci(95) ///
aspect(1) byopts(row(1)) ///
scheme(lean1) xtitle("Effect on Pr(Chosen in pairwise comparison)", size(small)) 

********************************************************************
* Preparations common for Figure 3-4: restricted sets of profiles  *
********************************************************************

gen all=use if conflicter==0
replace all=0 if conflicter==1 // The model for figure 3-4 is restricted 
// to the most attentitive respondents to avoid that noise creates a bias 
// towards 50 % (or rather 3/7) support for all groups.
// The all-variable above restricts all subsamples to the most attentitive 
// respondents, by excluding all responses from respondents that made 
// contradictory choices and ratings of profiles ("conflicter"). 

* Generating variables that indicate each relevant subset of profiles

gen cityresyincy=all if citizenshipyesprofile==1 & residentyesprofile==1 & incometaxyesprofile==1
gen cityresyincn=all if citizenshipyesprofile==1 & residentyesprofile==1 & incometaxyesprofile==0
gen cityresnincy=all if citizenshipyesprofile==1 & residentyesprofile==0 & incometaxyesprofile==1
gen cityresnincn=all if citizenshipyesprofile==1 & residentyesprofile==0 & incometaxyesprofile==0
gen citnresyincy=all if citizenshipyesprofile==0 & residentyesprofile==1 & incometaxyesprofile==1
gen citnresyincn=all if citizenshipyesprofile==0 & residentyesprofile==1 & incometaxyesprofile==0
gen citnresnincy=all if citizenshipyesprofile==0 & residentyesprofile==0 & incometaxyesprofile==1
gen citnresnincn=all if citizenshipyesprofile==0 & residentyesprofile==0 & incometaxyesprofile==0
gen optimalprofile=all if citizenshipyesprofile==1 & residentyesprofile==1 ///
& incometaxyesprofile==1 & usbornprofile==1 & mastersprofile==1	

* Generating and labelling a categorical subset variable 

gen subset=.
replace subset=8 if cityresyincy==1
replace subset=7 if cityresyincn==1
replace subset=6 if cityresnincy==1
replace subset=5 if cityresnincn==1
replace subset=4 if citnresyincy==1
replace subset=3 if citnresyincn==1
replace subset=2 if citnresnincy==1
replace subset=1 if citnresnincn==1
label define Profile 8 "Tax paying, resident citizens" ///
7 "Non-tax paying, resident citizens" 6 "Tax paying, non-resident citizens" ///
5 "Non-tax paying, non-resident citizens" 4 "Tax paying, resident non-citizens" ///
3 "Non-tax paying, resident non-citizens" 2 "Tax paying, non-resident non-citizens" ///
1 "Non-tax paying, non-resident non-citizens" 
label values subset Profile

******************************************************************
* Figure 3: Support for disenfranchising groups of U.S. citizens *
* in federal elections 				 							 *
******************************************************************

* Regressing subsets on preference for disenfranchising the profile
reg allowno i.subset if all==1 & subset>4$ses

* Mean preference for each subset, by margins 
margins, at(subset=(5(1)8))

marginsplot, horizontal yline(5(1)8, lwidth (vthin) lcolor(gray*.5)) ///
xline(0.5, lwidth (vthin)) graphregion(fcolor(white)) ///
ciopts(lcolor(black) lwidth(*1)) recast(dot) plotopts(ndots(1)) scheme(lean1) ///
xscale(range(0,1)) xlabel(0 "0%" 0.25 "25%" 0.5 "50%" 0.75 "75%" 1.0 "100%") ///
ytitle("") title("") xtitle("Support for disenfranchisement", size (medsmall)) aspect(.2)

**************************************************************
* Figure 4: Support for enfranchising groups of non-citizens *
* in federal elections. 									 *
**************************************************************

* Generating four more variables that indicate each new relevant subset of profiles

gen citnres15incy=all if citizenshipyesprofile==0 & us15profile==1 & incometaxyesprofile==1
gen citnres3incy=all if citizenshipyesprofile==0 & us3profile==1 & incometaxyesprofile==1
gen citnres15incn=all if citizenshipyesprofile==0 & us15profile==1  & incometaxyesprofile==0
gen citnres3incn=all if citizenshipyesprofile==0 & us3profile==1  & incometaxyesprofile==0

* Generating and labelling a categorical subset variable

gen allowyessubset=.
replace allowyessubset=6 if citnres15incy==1
replace allowyessubset=5 if citnres3incy==1
replace allowyessubset=4 if citnres15incn==1
replace allowyessubset=3 if citnres3incn==1
replace allowyessubset=2 if citnresnincy==1
replace allowyessubset=1 if citnresnincn==1
label define profileallowyess 6 "Tax paying, 15 years resident non-citizen" ///
5 "Tax paying, 3 years resident non-citizen" 4 "Non-tax paying, 15 years resident non-citizen" ///
3 "Non-tax paying, 3 years resident non-citizen" ///
2 "Tax paying, non-resident non-citizen" ///
1 "Non-tax paying, non-resident non-citizen" 
label values allowyessubset profileallowyess

* Regressing subsets on preference for disenfranchising the profile
reg allowyes i.allowyessubset if all==1 $ses

* Mean preference for each subset, by margins 
margins, at(allowyessubset=(1(1)6))

marginsplot, horizontal yline(1(1)6, lwidth (vthin) lcolor(gray*.5)) ///
xline(0.5, lwidth (vthin)) graphregion(fcolor(white)) ///
ciopts(lcolor(black) lwidth(*1)) recast(dot) plotopts(ndots(1)) scheme(lean1) ///
xscale(range(0,1)) xlabel(0 "0%" 0.25 "25%" 0.5 "50%" 0.75 "75%" 1.0 "100%") ///
ytitle("") title("") xtitle("Support for enfranchisement", size (medsmall)) aspect (.4)





********************************************************************************
*			2. Numbers that are referred to in the article w/o ref. to SI	   *
********************************************************************************

* 4.1 
* Correlation between attribute values
global profilelist "citizenshipyesprofile usbornprofile canadabornprofile mexicobornprofile philippnesbornprofile somaliabornprofile lessthanhighprofile highschoolprofile collegeprofile bachelorsprofile mastersprofile gendermanprofile incometaxyesprofile us15profile us3profile ustouristprofile europe15profile europe3profile"
corr  $profilelist if use==1 // For the largest correlation coefficient across 
// attributes (Pearson's r ≈ 0.02), see genderprofile and incometaxyesprofile) 
 
* 5.1 
* AMCEs for citizenship, residency and taxpaying 
reg chosen i.profilecitizenship i.profiletaxpayer  b5i.profileresidence ///
b5i.profileborn i.profileedu b2i.profilegender if use==1$ses

* AMCEs for being born in the USA rather than in Canada among only US citizen profiles
reg chosen b2i.profileborn i.profiletaxpayer  b5i.profileresidence ///
i.profileedu b2i.profilegender if use==1 &citizenshipyesprofile==1 $ses

* AMCE for interaction of gender and taxpaying
reg chosen i.profiletaxpayer##b2i.profilegender  i.profilecitizenship  ///
b5i.profileresidence b2i.profileborn i.profileedu if use==1$ses


* 5.2
* Support for disenfranchising groups of citizens
tab subset // N for groups of profiles rated by the most attentitive respondents
reg allowno i.subset if all==1 & subset>4$ses // Regressing subsets of 
// citizen-profiles on preference for disenfranchising the profile
margins, at(subset=(5(1)8)) // Mean preference for each subset

* Support for disenfranchising the group of U.S. citizens that should be 
* the least expected to have support for franchise. 
* a) most narrow group:
ci prop allowno if citizenshipyesprofile==1 & europe15profile==1 & incometaxyesprofile==0 & somaliabornprofile==1 & lessthanhighprofile==1 & all==1
* b) expanded group:
ci prop allowno if citizenshipyesprofile==1 & (europe15profile==1 | ustouristprofile==1)  & incometaxyesprofile==0 & (somaliabornprofile==1 | mexicobornprofile==1) & (lessthanhighprofile==1 | highschoolprofile) & all==1

* Support for enfranchising groups of non-citizens
tab allowyessubset // N for groups of non-citizen profiles 
// rated by the most attentitive respondents
reg allowyes i.allowyessubset if all==1 $ses // Regressing subsets of ///
// non-citizen profiles on preference for disenfranchising the profile
margins, at(allowyessubset=(1(1)6)) // * Mean preference for each subset


* Support for enfranchising the group of non-citizens that should be 
* the most expected to have support for franchise. 
* a) most narrow group:
ci prop allowyes if citizenshipyesprofile==0 & us15profile==1 & incometaxyesprofile==1 & usbornprofile==1 & mastersprofile==1 & all==1
* b) expanded group:
ci prop allowyes if citizenshipyesprofile==0 & residentyesprofile==1  & incometaxyesprofile==1 & (usbornprofile==1 | canadabornprofile==1) & (bachelorsprofile==1 | mastersprofile) & all==1


* END OF FILE *